import {createStore} from 'vuex'
// import {createStore} from './gvuex.js'
import {useRouter} from 'vue-router'

const store = createStore({
  state() {
    return {
      routers: [],
      removeRoutes: [],
      count: 6
    }
  },
  getters: {
    double(state) {
      return state.count * 2
    },
    getRouter(state) {
      return state.routers
    }
  },
  mutations: {
    add(state) {
      state.count++
    },
    SET_REMOVE_ROUTES(state, data) {
      debugger
      const removeRoutes = []
      // accessRoutes.forEach(route => {
      //   const removeRoute = router.addRoute(route)
      removeRoutes.push(data.tempRouter)
      // })
      state.removeRoutes = removeRoutes
      localStorage.removeRouters = JSON.stringify(removeRoutes)
      const router = data.router
      let routers = router.getRoutes().concat(removeRoutes)
      state.routers = routers
    }
  },
  actions: {
    asyncAdd({commit}) {
      setTimeout(() => {
        commit('add')
      }, 1000)
    },
    addRouter({commit}, data) {
      console.log('accessRoutes',data)
      commit('SET_REMOVE_ROUTES', data)
    },
  }
})

export default store
